package com.ecube.sql;

import com.ecube.mqtt.MqttUtils;
import com.ecube.mqtt.mysql.Query;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class StateCDZ3 {

    public static void main(String[] args) throws InterruptedException {
        int dcMeterElectAdd =34;
        int dcMeterElect = 0;

        while (true) {
            sendRealDataMQTT("FAT", "8880000000001111");
            dcMeterElect = dcMeterElectAdd + dcMeterElect;
            Thread.sleep(1000*30);
        }
    }
    public static void sendRealDataMQTT(String env, String chgID) {
        String productCode =Query.getPileCode(env, chgID);
        String pubTopic = productCode + chgID + "/S2M/state";
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateFormat.format(date);



        Random random = new Random();
        // 生成一个随机数，范围在0（包含）到1000（不包含）之间
        double minimum = 6000;
        double maximum = 2000;
        double randomNumber = minimum + (double) (Math.random() * maximum);
        // 格式化为两位小数
        String chgOutputVolt = String.format("%.2f", randomNumber);
        double minimum1 = 500;
        double maximum1 = 100;
        double randomNumber1 = minimum1 + (double) (Math.random() * maximum1);
        // 格式化为两位小数
        String chgOutputCurr = String.format("%.2f", randomNumber1);
        //仓位实时状态
        String content = "{\n" +
                "    \"dataBody\": {\n" +
                "        \"totalChgTime\": 5,\n" +
                "        \"MinTemp\": 20,\n" +
                "        \"soc\": 43,\n" +
                "        \"capacity\": 3446,\n" +
                "        \"voltDemand\": 450,\n" +
                "        \"remainderChgTime\": 89,\n" +
                "        \"chgVolt\": 0,\n" +
                "        \"currDemand\": 100,\n" +
                "        \"MinVoltNo\": -999,\n" +
                "        \"startTime\": \"2025-06-24 10:10:10\",\n" +
                "        \"vin\": \"YH471983721648818\",\n" +
                "        \"chgTime\": 20,\n" +
                "        \"chgOutputVolt\": " +chgOutputVolt+ ",\n" +
                "        \"batType\": 3,\n" +
                "        \"batID\": \"1\",\n" +
                "        \"chgOutputCurr\": 150,\n" +
                "        \"chgCode\": \""+chgID+"\",\n" +
                "        \"MaxVoltNo\": 0,\n" +
                "        \"totalChgCount\": 16777215,\n" +
                "        \"gunCodeArray\": [\n" +
                "            1,2\n" +
                "        ],\n" +
                "        \"snno\": 35,\n" +
                "        \"MaxVolt\": 3,\n" +
                "        \"chgQty\": 20,\n" +
                "        \"MinTempNo\": 0,\n" +
                "        \"MaxTemp\": 31,\n" +
                "        \"MinVolt\": -999,\n" +
                "        \"productCode\": \"100040002\",\n" +
                "        \"dcMeterElect\": 17,\n" +
                "        \"chgMode\": 2,\n" +
                "        \"MaxTempNo\": 0,\n" +
                "        \"chgCurr\": 0\n" +
                "    },\n" +
                "    \"header\": {\n" +
                "        \"timeStamp\": \"" +dateFormat.format(date)+ "\",\n" +
                "        \"reason\": 2,\n" +
                "        \"function\": \"chargeState\",\n" +
                "        \"index\": 35,\n" +
                "        \"version\": \"V1.0.8\"\n" +
                "    }\n" +
                "}";
        MqttUtils.sendMQTT(env, pubTopic, content);

    }
}
